package leecode.算法入门计划.day1;

/**
 * @author cloudJiang
 * @date 2021/10/24 16:59
 */
public class Num278 {
    boolean isBadVersion(int version) {
        return false;
    }

    public int firstBadVersion(int n) {
        int left = 1, right = n;
        int mid = 0;

        while (left < right) {
            // 等效 （left + right）/2 该写法可以防止int溢出
            mid = left + (right - left) / 2;
            if (isBadVersion(mid)) {
                right = mid;
            } else if (!isBadVersion(mid)) {
                left = mid + 1;
            }
        }

        return left;

       /* int left = 1, right = n;
        int mid = 0;

        while (left < right) {
            mid = left + (right - left) /2;
            if (isBadVersion(mid)) {
                right = mid;
            } else if (!isBadVersion(mid)) {
                left = mid + 1;
            }
        }

        return left;*/


    }
}
